import Vue from 'vue'
import Vuex from 'vuex'
import http from '../util/http.js'
import createPersistedState from "vuex-persistedstate"

Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState({
  reducer:(state)=>{
	  return{
		  cityId:state.cityId,
		  cityName:state.cityName
	  }
	}
  })],
  state: {
		cityId:'310100',
		cityName:'上海',
		cinema:[],
		footerShow:true
  },
  mutations: {
	  changeCityName(state, cityName){
		  state.cityName = cityName;
	  },
	  changeCityId(state, cityId){
	  		  state.cityId = cityId;
	  },
	  changeCinema(state, cinema){
		  state.cinema = cinema;
	  },
	  clearCityCinema(state){
		  state.cinema = []
	  },
	  show(state){
		  state.footerShow = true
	  },
	  notShow(state){
		  state.footerShow = false
	  }
  },
  actions: {
	  getCinemaData(store, id){
		  return http({
		  	url:`/gateway?cityId=${id}&ticketFlag=1&k=7962649`,
		  	headers:{
		  		'X-Host':'mall.film-ticket.cinema.list'
		  	}
		  }).then(res => {
			store.commit('changeCinema', res.data.data.cinemas);
		  })
	  }
  },
  modules: {
  }
})
